package com.compass.doctor.ui.consultation.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.doctor.callback.OnTextChanged
import com.compass.doctor.databinding.LayoutJoinDoctorItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseRecyclerViewAdapter
import com.compass.framework.ext.onClick
import com.compass.framework.glide.setUrlCircle
import com.compass.framework.model.Doctor

/**
 * Description： 已加入的医生 adapter
 * Date:2023/12/22 13:58
 */
class JoinDoctorAdapter : BaseRecyclerViewAdapter<Doctor, LayoutJoinDoctorItemBinding>() {


    private lateinit var onTextChanged: OnTextChanged
    fun setOnChangedCallBack(textChanged: OnTextChanged) {
        this.onTextChanged = textChanged
    }

    private var onCustomBottomClick: OnCustomButtonClick? = null
    fun setOnCustomBottomClick(onCustomBottomClick: OnCustomButtonClick?) {
        this.onCustomBottomClick = onCustomBottomClick
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<LayoutJoinDoctorItemBinding>,
        item: Doctor?,
        position: Int
    ) {
        if (item == null) return
        holder.binding.apply {
            tvDoctorName.text = item.name
            edtExpense.text = item.medicalConsultationPrice
            imgDoctorHead.setUrlCircle(item.avatar)
            tvRank.text = item.positionName
            tvHospital.text = "${item.hospitalName}  ${item.departmentName}"
            imgDelete.onClick {
                onCustomBottomClick?.onButtonCallBack(position, "delete")
            }
//            edtExpense.requestFocus()
//            item.expense?.let {
//                edtExpense.setText(item.expense)
//            }?:{
//                edtExpense.setText("")
//            }
//
//            if (edtExpense.tag is TextWatcher) {
//                edtExpense.removeTextChangedListener(edtExpense.tag as TextWatcher)
//            }
//
//
//            val filter = MoneyInputFilter()
//            filter.setMaxValue(1000.00)
//            edtExpense.filters = arrayOf(filter)
//            val textWatcher = object : TextWatcher {
//                override fun beforeTextChanged( s: CharSequence?, start: Int,count: Int, after: Int) {
//                }
//
//                override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
//                }
//                override fun afterTextChanged(s: Editable?) {
//                    var cost = edtExpense.text.toString()
//                    if (cost.isNotEmpty()) item.expense = cost else item.expense = ""
//                    onTextChanged.onTextChange()
//                }
//            }
//            edtExpense.addTextChangedListener(textWatcher)
//            edtExpense.tag = textWatcher


        }
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutJoinDoctorItemBinding {
        return LayoutJoinDoctorItemBinding.inflate(layoutInflater, parent, false)
    }
}